package com.myh.exam.controller;

import com.myh.exam.dto.User;
import com.myh.exam.service.UserService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/findUser")
public class FindUserServlet extends HttpServlet {

    private UserService userService = new UserService();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Integer id = Integer.valueOf(req.getParameter("id"));
        User result = userService.selectUser(id);
        if (result == null) {
            req.getRequestDispatcher("error.jsp").forward(req, resp);
        } else {
            //1.获取列表数据
            //2.将数据传给下一个页面
            req.setAttribute("name", result.getName());
            req.setAttribute("nickName", result.getNickName());
            req.setAttribute("passwd", result.getPasswd());
            req.setAttribute("id", result.getId());
            req.getRequestDispatcher("editUser.jsp").forward(req, resp);
        }
    }
}
